﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class user_login : System.Web.UI.Page
{
    public string strcr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["teacherId"] != null)
            {
                Response.Redirect("../teacher/index.aspx");
            }
        }
        catch { }
        db_blogroll blogroll = new db_blogroll();
        DataSet ds_blogroll = blogroll.selectBlogrollALL();
        blogrollList.DataSource = ds_blogroll.Tables[0].DefaultView;
        blogrollList.DataBind();

        db_copyright cr = new db_copyright();
        DataSet dscr = cr.selectOne();
        strcr = "Copyright &copy; " + dscr.Tables[0].Rows[0]["cryear"].ToString() + " " + dscr.Tables[0].Rows[0]["owner"].ToString() + " ALL Rights Reserved<br/><a href=\"http://www.miibeian.gov.cn\" target=\"_blank\">" + dscr.Tables[0].Rows[0]["approve"].ToString() + "</a>";

    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        string name = Tools.Clearstr(tb_userID.Text, 20);
        string pwd = Tools.Clearstr(tb_userPwd.Text, 20);
        string code = Tools.Clearstr(tb_code.Text, 20);
        bool isErrorCode = true;
        try
        {

            if (code != Session["teach"].ToString()) //判断验证码是否正确
            {
                isErrorCode = true;//如果不正确，则为true
            }
            else
            {
                isErrorCode = false;
            }
        }
        catch
        {
            Response.Write("<script language=javascript>alert('验证码超时，请重新登录！');top.location.href='../teacher/login.aspx';</script>");
        }

        if (isErrorCode)
        {
            Response.Write("<script language=javascript>alert('验证码错误！！！');top.location.href='../teacher/login.aspx';</script>");
        }
        else
        {
            db_teacher teach = new db_teacher();
            string[] Info = teach.isLogin(name, Tools.mymd5(pwd));
            if (Info != null)
            {
                Session["teacherId"] = name;
                Session["teacherName"] = Info[0];
                Session["lastTime"] = Info[1];
                Response.Redirect("../teacher/index.aspx");
            }
            else
            {
                Session["teacherId"] = null;
                Session["lastTime"] = null;
                Session["lastTime"] = null;
                Response.Write("<script language=javascript>alert('用户名或密码错误，登陆不成功！！！');top.location.href='../teacher/login.aspx';</script>");
            }
        }
    }
}